package com.gmall.console.base;

import com.gmall.console.common.DataCons;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @description: 统一返回结果
 * @author: Jone
 * @create: 2024-05-27
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private Integer code;
    private String message;
    private T data;

    /**
     * 成功返回
     */
    public static <T> Result<T> success(){
        return new Result<T> (DataCons.MSG_CODE_200,"success",null);
    }
    public static <T> Result<T> success(T data){
        return new Result<T> (DataCons.MSG_CODE_200,"success",data);
    }
    public static <T> Result<T> success(String message){
        return new Result<T> (DataCons.MSG_CODE_200,message,null);
    }
    public static <T> Result<T> success(T data ,String message){
        return new Result<T> (DataCons.MSG_CODE_200,message,data);
    }

    /**
     * 失败返回
     */
    public static <T> Result<T> fail(){
        return new Result<T> (DataCons.MSG_CODE_201,"fail",null);
    }
    public static <T> Result<T> fail(String message){
        return new Result<T> (DataCons.MSG_CODE_201,message,null);
    }
    public static <T> Result<T> fail(int code,String message){
        return new Result<T> (code,message,null);
    }
}
